home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 58189 / 58189.xpi / chrome / content / overlay.js next >
Text File  |  2010-01-06  |  2KB  |  63 lines

  1. /*
  2.  * This overlay listens for mouse clicks on links or form submissions. Whenever
  3.  * a user initiates such an action, the information about this action is relayed
  4.  * to the Policy Information Point for later use.
  5.  *
  6.  * This code is heavily inspired by the "RequestPolicy" extension
  7.  */
  8.  
  9. Components.utils.import("resource://csfiremodules/CsFireCommon.jsm");
  10.  
  11. CsFire.Overlay = new function() {};
  12.  
  13. /*
  14.  * This function will be executed at a load event. It will filter link clicks and
  15.  * form submissions and ignore other actions.
  16.  */
  17. CsFire.Overlay.onLoad = function(event) {
  18.     try {
  19.         var appcontent = document.getElementById("appcontent");
  20.     
  21.         /*
  22.          * Register left mouse clicks on links. According to the developer information
  23.          * it's not possible to automate user-initiated clicks.
  24.          *
  25.          * http://developer.mozilla.org/en/DOM/element.click
  26.          */
  27.         appcontent.addEventListener("click", function(event) {
  28.             // We're only interested in left-clicks on anchor tags.
  29.             if(event.target.nodeName.toLowerCase() == "a" && event.button == 0) {
  30.                 CsFire.CsFireController.registerUserInteraction(event.target.href, event.target.ownerDocument.URL);
  31.             }     
  32.         }, true);
  33.  
  34.         /*
  35.          * Register human-initiated form submissions. According to the author of
  36.          * RequestPolicy, automatic form submission does not fire this event. After
  37.          * verification, we have come to the same conclusion.
  38.          */
  39.         appcontent.addEventListener("submit", function(event) {
  40.             if (event.target.nodeName.toLowerCase() == "form") {
  41.                 CsFire.CsFireController.registerUserInteraction(event.target.action, event.target.ownerDocument.URL);
  42.             }
  43.         }, true);
  44.     }
  45.     catch(e) {
  46.         CsFire.Logger.error("Error registering user interaction listeners: " + e);
  47.     }
  48. };
  49.  
  50. /*
  51.  * Triggers the code to be run after an update or installation
  52.  * Needs to be here, to ensure that everything has loaded before it is executed
  53.  */
  54. CsFire.Overlay.onInstallOrUpdate = function() {
  55.     CsFire.CsFireController.performInstallAction();
  56.     window.removeEventListener("load",function(){ CsFire.Overlay.onInstallOrUpdate(); },true);
  57. }
  58. /*
  59.  * Register the event listener for user events whenever a page loads.
  60.  */
  61. addEventListener("load", function(event) { CsFire.Overlay.onLoad(event); }, false);
  62. window.addEventListener("load",function(){ CsFire.Overlay.onInstallOrUpdate(); },true);
  63.